<#include '/admin/header.html' >
<style>
.receiptsInputText{
    width: 35px;
    height: 20px;
    border: 1px solid #ccc;
    border-radius: 3px;
   	text-align:center;
   	
}
</style>

<script type="text/javascript" src="${ctx}/floor/admin/js/showcase.js"></script>
	<div class="admin-main">
    	<div>
    	  <!-- 提示区域 -->
       	  <div class="page_explain">
           	<h2>操作提示</h2>
            <ul>
                <li><span>·</span>橱窗列表中，可以添加、删除、排序、编辑、显示等功能。</li>
                <li><span>·</span>在添加，或者修改橱窗的同时，您可以选择是否显示，和添加多个商品，保存之后，如果是显示的话，前台就会出现相应橱窗。</li>
                <li><span>·</span>可以添加多个橱窗，想要更改先后顺序，您可以用排序来实现。</li>
                <li><span>·</span>列表中“显示” 菜单中，您可以直接点击显示，与未显示来切换显示状态，前台刷新即生效。</li>
            </ul>
          </div>
         <!--  按钮区域 -->
          	<div class="table_control">
            	<div class="table_opera">
                	<button type="button" id="add_showcase_button" title="添加" onclick='newTab("添加橱窗","${ctx}/core/admin/showcase/add-showcase.do");'class="layui-btn layui-btn-primary "><i class="icon iconfont icon-llalbumshopselectorcreate"></i></button>
                	<button type="button" id="save-subject-sort" title="保存排序" class="layui-btn layui-btn-primary " onclick="saveSort()"><i class="icon iconfont icon-xuanze"></i></button>
                	<button type="button"  title="提示" class="layui-btn layui-btn-primary " id="explain"><i class="icon iconfont icon-tishi1"></i></button>
            	</div>
        	</div>
        </div>
        <!--   表格区域 -->
    	<form action="" id="gridform">
			<table id="showcasedata" class="layui-table site-table table-hover" width="100%" lay-skin="line">
        		<thead>
        			<tr>
        			<th><input type='checkbox'  class='btn-checkall fly-checkbox' id='selected-all'></th>
            		<th>排序</th>
            		<th>橱窗名称</th>
            		<th>橱窗标识</th>
            		<th>显示</th>
            		<th>编辑</th>
            		<th>删除</th>
        			</tr>
        		</thead>
   		 	</table>
		</form>

	</div>

<script>
var table;
$(function(){
	table = $('#showcasedata').DataTable({
		"language": {
	        "url": "${staticserver}/media/zh_CN.txt"
	    },
	    "processing": true,
	    "serverSide": true,
	    "ordering": false,
	    "searching": false,
	    "lengthChange": false,
	    ajax: {
	        //指定数据源
	        type:"post",
	        dataType : 'json',
	        url: "${ctx}/core/admin/showcase/list-json.do",
	    },
	    columns: [ //定义列
	             {"data": function (obj) {
	                   return '<input type="checkbox" name="id" class="fly-checkbox" value=' + obj.id + '>';
	               	}},
	             {data: null,"render": function(data,type,row){
	            	 var val = '<input type="text" class="receiptsInputText" autocomplete="off" onblur="onlyNumber(this,'+row.sort+','+row.id+')" value="'+row.sort+'"  name="showcase_sorts" maxlength="9">';
	            		val+='<input type="hidden" name="showcase_ids" value="'+row.id+'" > '
	            		return val;
	             }},
	             {data: "title"},
	             {data: "flag"},
	             {data: null,"render": function(obj) {
	               	 	var val = "";
	               	 	if(obj.is_display == 0){
	               		 val = '<p id="subjectstatus'+obj.id+'" style="display:inline;margin:0px 10px">已显示</p>'
	            			+'<input class="stop button layui-btn layui-btn-danger layui-btn-small" type="button" value="停用" floorid="'+obj.id+'" id=subjectimg'+obj.id+' onclick="changeshow('+obj.id+')" showvalue="0" changevalue="1" >';
	               		}else if(obj.is_display == 1){
	               			val = '<p id="subjectstatus'+obj.id+'" style="display:inline;margin:0px 10px">未显示</p>'
	               			+'<input class="start button layui-btn layui-btn-normal layui-btn-small" type="button" value="启用" floorid="'+obj.id+'" id=subjectimg'+obj.id+' onclick="changeshow('+obj.id+')" showvalue="1" changevalue="0" >';
	               		}
	               	 	return val;
	    	 	 }},
	             {data: null,"render": function(obj) {
	 	        	return "<a class='layui-btn layui-btn-small layui-btn-normal'  name='change_btn' onclick='newTab(\""+obj.title+"橱窗修改\",\"${ctx}/core/admin/showcase/edit-showcase.do?id="+obj.id+"\")' >编辑</a>"	
	 	        	
	 	       	}},
	             {data: null,"render": function(obj) {
	 	        	return "<a class='layui-btn layui-btn-small layui-btn-danger'  onclick='del("+ obj.id + ")'><img floorid='"+obj.id+"' src='"+ctx+"/shop/admin/images/transparent.gif'>删除</a>";		
	 	       	}}
	     ]
	});
	
});

//删除
function del(id){
	var check = $("input[name='id']").is("input:checked");
	if(!confirm("确认要删除该橱窗吗？")){
		return;
	}
	var options = {
			url:ctx+"/core/admin/showcase/delete.do?id=" + id,
			type:"post",
			dataType:"json",
			success:function(data){
				if(data.result==1){
					$.Loading.success(data.message);
					table.ajax.url(ctx+"/core/admin/showcase/list-json.do").load();
				}
				if(data.result==0){
					$.Loading.error(data.message);
				}
			}
	};
	$("#gridform").ajaxSubmit(options);
}
//保存排序  
function saveSort(){
	//var check = $("input[name='id']").is("input:checked");
	
	var obj = document.getElementsByName("id");
    var check_val = [];
    var check_sorts =[]; 
    for(k in obj){
        if(obj[k].checked){
        	check_val.push(obj[k].value);
        	var sorts=$(obj[k]).parent().parent().find("input[name='showcase_sorts']").val();
        	check_sorts.push(sorts);
        }
   	}
    if(check_val.length == 0){
    	alert("保存失败！请选择您要保存的排序！！");
    	return false;
    }
	$.ajax({
		url:"${ctx}/core/admin/showcase/save-sort.do?showcase_ids="+check_val+"&showcase_sorts="+check_sorts,
		type : "POST",
		dataType : 'json',
		success : function(result) {	
			if (result.result == 1) {	
				$.Loading.success("保存成功！！")
				table.ajax.reload();
			}
			if (result.result == 0) {
				$.Loading.error(result.message);
			}
		},
		error : function(e) {
			$.Loading.error("出现错误 ，请重试");
		}
	});
}

</script>
<#include '/admin/footer.html' >